<!doctype html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Critical FOFT</title>
	<style>
	@font-face {
		font-family: LatoSubset;
		src: url('font-lato/lato-zachleat-optimized.woff2') format('woff2'),
				 url('font-lato/lato-zachleat-optimized.woff') format('woff');
		unicode-range: U+65-90, U+97-122;
	}
	@font-face {
		font-family: Lato;
		src: url('font-lato/lato-regular-webfont.woff2') format('woff2'),
				 url('font-lato/lato-regular-webfont.woff') format('woff');
	}

	@font-face {
		font-family: Lato;
		src: url('font-lato/lato-bold-webfont.woff2') format('woff2'),
				 url('font-lato/lato-bold-webfont.woff') format('woff');
		font-weight: 700;
	}

	@font-face {
		font-family: Lato;
		src: url('font-lato/lato-italic-webfont.woff2') format('woff2'),
				 url('font-lato/lato-italic-webfont.woff') format('woff');
		font-style: italic;
	}

	@font-face {
		font-family: Lato;
		src: url('font-lato/lato-bolditalic-webfont.woff2') format('woff2'),
				 url('font-lato/lato-bolditalic-webfont.woff') format('woff');
		font-weight: 700;
		font-style: italic;
	}

	body {
		font-family: sans-serif;
	}
	.fonts-loaded-1 body {
		font-family: LatoInitial;
	}
	.fonts-loaded-2 body {
		font-family: Lato;
	}
	</style>
	<script>
	(function() {
		if( "fonts" in document ) {
			// Optimization for Repeat Views
			if( sessionStorage.fontsLoadedCriticalFoft ) {
				// only stage 2 needed here, the subset isn’t needed anymore
				document.documentElement.className += " fonts-loaded-2";
				return;
			}

			document.fonts.load("1em LatoSubset").then(function () {
				document.documentElement.className += " fonts-loaded-1";

				Promise.all([
					document.fonts.load("400 1em Lato"),
					document.fonts.load("700 1em Lato"),
					document.fonts.load("italic 1em Lato"),
					document.fonts.load("italic 700 1em Lato")
				]).then(function () {
					document.documentElement.className += " fonts-loaded-2";

					// Optimization for Repeat Views
					sessionStorage.fontsLoadedCriticalFoft = true;
				});
			});
		}
	})();
	</script>
</head>
<body>
	<h1>Critical FOFT</h1>
	<p>This is a paragraph. <strong>This is heavier text.</strong> <em>This is emphasized text.</em> <strong><em>This is heavier and emphasized text.</em></strong></p>

	<hr style="margin-top: 2em">
	<ul>
		<li>This demo is a companion to <a href="https://www.zachleat.com/web/comprehensive-webfonts/">A Comprehensive Guide to Font Loading Strategies</a></li>
		<li>See all demos on <a href="https://github.com/zachleat/web-font-loading-recipes">GitHub <code>zachleat/web-font-loading-recipes</code></a></li>
	</ul>
</body>
</html>